package de.riceman.simpleGo.view.dialogs;

import org.springframework.richclient.dialog.TabbedDialogPage;
import org.springframework.richclient.dialog.TitledPageApplicationDialog;

import de.riceman.simpleGo.events.SimpleGoLifecycleApplicationEvent;
import de.riceman.simpleGo.main.NewGameSetup;
import de.riceman.simpleGo.view.forms.NewGameForm;
 
public class NewGameDialog extends TitledPageApplicationDialog {
 
	TabbedDialogPage compositePage;
	NewGameForm newGameForm;
	
	public NewGameDialog(TabbedDialogPage compositePage, NewGameForm newGameForm) {
		super(compositePage);
		this.compositePage = compositePage;
		this.newGameForm = newGameForm;
	}
	
	protected void onAboutToShow() {
		String title =
			getMessage(
					"newGameProperties.edit.title",
					new Object[]{
							"bla",
							"blubb"
					});
		setTitle(title);
		
        setEnabled(compositePage.isPageComplete());
    }

	protected boolean onFinish() {
        newGameForm.getFormModel().commit();
        
        NewGameSetup newGameSetup = (NewGameSetup) newGameForm.getFormObject();
        
        getApplicationContext().publishEvent(
        		new SimpleGoLifecycleApplicationEvent(SimpleGoLifecycleApplicationEvent.CREATED, newGameSetup));
        
        return true;
    }
	
	@Override
	protected void onCancel() {
		super.onCancel();
	}
	
     
}